import { http } from "..";

const api = http('sys')

const LOGIN_TYPE = 'wx'
const REQUEST_TOKEN_KEY = 'Authorization'
const REQUEST_RTOKEN_KEY = 'RAuthorization'
const REQUEST_TOKEN_PRE = 'Bearer'

/**
 * 刷新token
 * @param {String} rtoken
 */
export const refreshToken = (rtoken) => {
	if (!rtoken) return Promise.reject({ code: -1, message: '参数错误' })
	return api({
		url: `/login/refresh/${LOGIN_TYPE}`,
		header: {
			[REQUEST_RTOKEN_KEY]: rtoken
		},
		method: 'post',
		hideToken: true, // 不携带token
	})
}

/**
 * 登出
 * @param {String} rtoken
 */
export const logout = (rtoken) => {
	if (!rtoken) return Promise.reject({ code: -1, message: '参数错误' })
	return api({
		url: '/logout',
		method: 'post',
		header: {
			'Content-Type': 'text/plain'
		},
		data: rtoken
	})
}